<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/5
 * Time: 11:57
 */

namespace app\home\controller;
use app\home\model\AmountLog;
use app\home\model\GoodsOrder;
use app\home\model\HomeModule;
use app\home\model\HomeTemplate;
use app\home\model\IntegralLog;
use app\home\model\Level;
use app\home\model\PackageOrder;
use app\home\model\Recharge;
use app\home\model\Sms;
use  app\home\model\User as UserModel;
use app\home\model\UserCommission;
use app\home\model\UserToken;
use app\merchant\model\UserConsumption;
use app\services\jwt\JwtService;
use app\services\wechat\Offiaccount;
use dh2y\qrcode\QRcode;
use think\Request;
use think\Validate;

class User
{


    public function userInfo(Request $request)
    {
        $param = $request->param();
        $uid = $param['id'];
        $userModel = new UserModel();
        $user = $userModel->where(['id' => $uid])->find();
        if (empty($user)){
            return error('用户不存在');
        }
        $tokenModel = new UserToken();
        $authInfo = $tokenModel->where(['uid'=> $uid ,'type' => 1])->order('effective_time','desc')->find();
        $url = getProtocol() . $_SERVER["HTTP_HOST"].'/home.php/wechatLogin?url=H5/index.html&invite='.$user['invite_code'];
        $QRcode = new QRcode();
        $imageString = $QRcode->png($url, './uploads/qrcode/'.$user['invite_code'].'.png', "2", 4, 1)->entry();
        $user['invite_url'] = $imageString;

        if (empty($authInfo)){
            $jwt = new JwtService();
            //根据用户id生成token
            $token = $jwt->getToken($uid, 30);  //获取token
            $tokenConfig = ['uid' => $uid, 'token' => $token, 'create_time' => time(),
                'effective_time' => time() + 60 * 60 * 24 * 30, 'login_ip' => $request->ip(), 'type' => 1];  //token配置信息  //token配置信息
            $tokenModel->insert($tokenConfig);  //更新token
        }else{
            $token = $authInfo['token'];
        }


        $user['token'] =$token;
        return success('用户信息', $user);
    }

    /**
     *   手机号登录/注册
     */
    public function login(Request $request)
    {
        $param = $request->param();
        $phone = $param['phone'];
        if (empty($phone)) {
            return error('请填写手机号码');
        }
        $userModel = new UserModel();
        $user = $userModel->where(['phone' => $phone])->find();

        if (!isset($param['code']) || empty($param['code'])) {
            return error('请填写短信验证码');
        }
        $smsInfo = Sms::checkCode($param['phone'], $param['code'], '1');
        if ($smsInfo['code'] != 1000) {
            return error($smsInfo['msg']);
        }
        /*   try {*/
        if ($user) {
            if ($user['status'] != 1) {
                return error("账号未启用,请联系管理员", [], '204');
            }
            $userDate['last_login_ip'] = request()->ip();
            $userDate['last_login_time'] = time();
            $userModel->where(['id' => $user['id']])->update($userDate);
            $id = $user['id'];
        } else {
            if (isset($param['invite_code']) && !empty($param['invite_code'])) {
                $superior_user = $userModel->where(['invite_code' => $param['invite_code']])->find();
                $userDate['pid'] = $superior_user['id'];
                $userDate['pids'] = $superior_user['pids'] . ',' . $superior_user['id'];
            }
            $userDate['register_ip'] = request()->ip();
            $userDate['create_time'] = time();
            $userDate['nickname'] = time();
            $userDate['invite_code'] = $this->getRandCode(6);
            $userDate['phone'] = $param['phone'];
            $userDate['avatar'] = 'www.baidu.com';
            $userModel->insert($userDate);
            $id = $userModel->getLastInsID();
            $userModel->updateUserLevel($id, 1);
        }
        $jwt = new JwtService();
        //根据用户id生成token
        $token = $jwt->getToken($id, 30);  //获取token
        $tokenConfig = ['uid' => $id, 'token' => $token, 'create_time' => time(),
            'effective_time' => time() + 60 * 60 * 24 * 30, 'login_ip' => $request->ip(), 'type' => 1];  //token配置信息  //token配置信息
        $tokenModel = new UserToken();
        $user = $userModel->where(['phone' => $phone])->find();

        $tokenModel->insert($tokenConfig);  //更新token
        $user['token'] = $token;
        return success('登录成功', $user);
        /* } catch (\Exception $e) {
             return error($e->getMessage() . $e->getLine());
         }*/
    }

    protected function getRandCode($num = 6)
    {
        $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
        $str = '';
        for ($i = 0; $i < $num; $i++) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }
        $userModel = new UserModel();
        $user = $userModel->where(['invite_code' => $str])->find();
        if ($user) {
            self::getRandCode($num);
        }
        return $str;
    }

    /**
     * 发送短信
     */
    public function smsCode(Request $request)
    {
        /*   try {*/
        $smsModel = new Sms();
        $expire = 60;
        $maxSendNums = 5;
        $param = $request->param();
        if (!$param['phone'] || !(new Validate())->rule($param['phone'], '^1\d{10}$')) {
            return error('手机号不正确');
        }
        $lastSend = $smsModel->where(['phone' => $param['phone'], 'type' => '1'])->find();
        if ($lastSend && time() - $lastSend['create_time'] < $expire) {
            return error('发送频繁');
        }
        $ipSendTotal = $smsModel->where(['ip' => request()->ip()])->whereTime('create_time', '-1 hours')->count();
        if ($ipSendTotal >= $maxSendNums) {
            return error('发送频繁');
        }
        $code = mt_rand(1000, 9999);
        $ip = request()->ip();
        $smsModel->startTrans();
        $sms = $smsModel->save(['type' => '1', 'phone' => $param['phone'], 'code' => $code, 'ip' => $ip]);
        if ($sms === false) {
            $smsModel->rollback();
            return error('发送失败');
        }
        /**
         *  三方接口
         */
        if (true) {
            $smsModel->commit();
            return success('发送成功');
        } else {
            $smsModel->rollback();
        }
        /*   } catch(Exception $e) {
               throw new Exception($e->getMessage());
           }*/
    }

    public function updateUser(Request $request)
    {
        $uid = $request->userInfo['id'];
        $userModel = new UserModel();
        $param = $request->param();
        $data = [

            'phone' => $param['phone'],
            'real_name' => $param['real_name'],
            'sex' => $param['sex'],
            'birthday' => $param['birthday'],
            'province_id' => $param['province_id'],
            'city_id' => $param['city_id'],
            'area_id' => $param['area_id'],
            'province_name' =>  $param['province_name'],
            'city_name' =>  $param['city_name'],
            'area_name' =>  $param['area_name'],
        ];
        $userInfo = $userModel->where('id' ,'<>', $uid)->where(['phone' =>  $param['phone']])->find();
        if ($userInfo){
            return error('账号已存在');
        }
        $userModel->where(['id' => $uid])->update($data);
        return success('修改成功');
    }

    /**
     * 直推用户
     */
    public function fans(Request $request)
    {
        $param = $request->param();
        $userModel = new \app\home\model\User();
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $where[] = ['pid','=',$request->userInfo['id']];
        if (isset($param['name']) && !empty($param['name'])) {
            $where[] = ['phone|wachat_nickname', 'like', '%' . $param['name'] . '%'];
        }
        $userList = $userModel->where($where)
            ->field('id,avatar,wachat_nickname,nickname,phone,create_time')->limit($start, $limit)->select()->toArray();
        $count = $userModel->where($where)->count();
        if ($userList) {
            $userIds = array_column($userList, 'id');
            ;
            $userCommissionModel = new UserCommission();
            $goodsOrderModel  = new GoodsOrder();
            $goodsOrderList = $goodsOrderModel
                ->where('user_id','in',$userIds)
                ->where('status','=',6)
                ->group('user_id')
                ->field('user_id,sum(reality_amount) as reality_amount, count(id) as count')->select()->toArray();
            $goodsOrderListById= [];
            if ($goodsOrderList){
                $goodsOrderListById = array_column($goodsOrderList,null,'user_id');
            }
            $refundOrderCount =  $goodsOrderModel
                ->where('user_id','in',$userIds) ->where('status','=',7)
                ->field('user_id, count(id) as count')
                ->group('user_id')
                ->select()->toArray();
            $refundOrderCountByUserId =[];
            if ($refundOrderCount){
                $refundOrderCountByUserId = array_column($refundOrderCount,null,'user_id');
            }

            $packageOrderModel  = new PackageOrder();
            $packageOrderList = $packageOrderModel
                ->where('uid','in',$userIds)
                ->where('status','=',3)
                ->group('uid')
                ->field('uid,sum(price) as price ,count(id) as count')->select()->toArray();
            $packageOrderListById = [];
            if ($packageOrderList){
                $packageOrderListById  = array_column($packageOrderList,null,'uid');
            }
            $userCommission = $userCommissionModel
                ->where('trigger_uid', 'in', $userIds)
                ->field('trigger_uid,sum(amount) as amount')
                ->where('receive_uid', '=', $request->userInfo['id'])
                ->group('trigger_uid')->select()->toArray();
            $userCommissionById = [];
            if ($userCommission) {
                $userCommissionById = array_column($userCommission, null, 'trigger_uid');
            }
            foreach ($userList as $key => $item) {
                if (array_key_exists($item['id'], $userCommissionById)) {
                    $userList[$key]['amount'] = $userCommissionById[$item['id']]['amount'];
                } else {
                    $userList[$key]['amount'] = 0;
                }
                if (array_key_exists($item['id'], $goodsOrderListById)) {
                    $userList[$key]['consumption_amount'] = $goodsOrderListById[$item['id']]['reality_amount'];
                    $userList[$key]['order_count'] =  $goodsOrderListById[$item['id']]['count'];
                } else {
                    $userList[$key]['consumption_amount'] = 0;
                    $userList[$key]['order_count'] = 0;
                }
                if (array_key_exists($item['id'], $refundOrderCountByUserId)) {
                    $userList[$key]['refund_order_count'] =$refundOrderCountByUserId[$item['id']]['count'];
                } else {
                    $userList[$key]['refund_order_count'] =0;
                }

                if (array_key_exists($item['id'], $packageOrderListById)) {
                    $userList[$key]['consumption_amount'] += $packageOrderListById[$item['id']]['price'];
                    $userList[$key]['order_count'] +=  $packageOrderListById[$item['id']]['count'];
                }


            }
        }
        return success('直推用户列表', ['list' => $userList, 'count' => $count]);
    }

    /**
     * 间推用户
     */
    public function secondFans(Request $request)
    {
        $param = $request->param();
        $userModel = new \app\home\model\User();
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $userList = $userModel->where(['pid' => $request->userInfo['id']])->field('id,avatar,wachat_nickname,nickname,avatar,phone,create_time')->limit($start, $limit)->select()->toArray();
        $count = 0;
        $secondFans = [];
        if ($userList) {
            $userIds = array_column($userList, 'id');
            $userById = array_column($userList, null, 'id');
            $where[] = ['pid','in',$userIds];
            if (isset($param['name']) && !empty($param['name'])) {
                $where[] = ['phone|wachat_nickname', 'like', '%' . $param['name'] . '%'];
            }
            $secondFans = $userModel->where($where)->field('id,avatar,wachat_nickname,nickname,avatar,phone,pid,create_time')->limit($start, $limit)->select()->toArray();
            $count = $userModel->where($where)->count();
            if ($secondFans) {

                $secondFansIds = array_column($secondFans, 'id');
                $goodsOrderModel  = new GoodsOrder();
                $goodsOrderList = $goodsOrderModel
                    ->where('user_id','in',$secondFansIds)
                    ->where('status','=',6)
                    ->group('user_id')
                    ->field('user_id,sum(reality_amount) as reality_amount, count(id) as count')->select()->toArray();
                $goodsOrderListById= [];
                if ($goodsOrderList){
                    $goodsOrderListById = array_column($goodsOrderList,null,'user_id');
                }
                $refundOrderCount =  $goodsOrderModel
                    ->where('user_id','in',$secondFansIds) ->where('status','=',7)
                    ->field('user_id, count(id) as count')
                    ->group('user_id')
                    ->select()->toArray();
                $refundOrderCountByUserId =[];
                if ($refundOrderCount){
                    $refundOrderCountByUserId = array_column($refundOrderCount,null,'user_id');
                }

                $packageOrderModel  = new PackageOrder();
                $packageOrderList = $packageOrderModel
                    ->where('uid','in',$secondFansIds)
                    ->where('status','=',3)
                    ->group('uid')
                    ->field('uid,sum(price) as price ,count(id) as count')->select()->toArray();
                $packageOrderListById = [];
                if ($packageOrderList){
                    $packageOrderListById  = array_column($packageOrderList,null,'uid');
                }
                $userCommissionModel = new UserCommission();
                $userCommission = $userCommissionModel
                    ->where('trigger_uid', 'in', $secondFansIds)
                    ->field('trigger_uid,sum(amount) as amount')
                    ->where('receive_uid', '=', $request->userInfo['id'])
                    ->group('trigger_uid')->select()->toArray();
                $userCommissionById = [];
                if ($userCommission) {
                    $userCommissionById = array_column($userCommission, null, 'trigger_uid');
                }  //var_dump($userCommission);exit;
                foreach ($secondFans as $key => $item) {
                    if (array_key_exists($item['id'], $userCommissionById)) {
                        $secondFans[$key]['amount'] = $userCommissionById[$item['id']]['amount'];
                    } else {
                        $secondFans[$key]['amount'] = 0;
                    }
                    if (array_key_exists($item['id'], $goodsOrderListById)) {
                        $secondFans[$key]['consumption_amount'] = $goodsOrderListById[$item['id']]['reality_amount'];
                        $secondFans[$key]['order_count'] = $goodsOrderListById[$item['id']]['count'];

                    } else {
                        $secondFans[$key]['consumption_amount'] = 0;
                        $secondFans[$key]['order_count'] = 0;

                    }
                    if (array_key_exists($item['id'], $refundOrderCountByUserId)) {
                        $secondFans[$key]['refund_order_count'] =$refundOrderCountByUserId[$item['id']]['count'];
                    } else {
                        $secondFans[$key]['refund_order_count'] =0;
                    }
                    if (array_key_exists($item['id'], $packageOrderListById)) {
                        $secondFans[$key]['consumption_amount'] += $packageOrderListById[$item['id']]['price'];
                        $secondFans[$key]['order_count'] +=  $packageOrderListById[$item['id']]['count'];
                    }
                    $secondFans[$key]['pid_nickname'] = $userById[$item['pid']]['nickname'];
                    $secondFans[$key]['pid_avatar'] = $userById[$item['pid']]['avatar'];
                    $secondFans[$key]['pid_wachat_nickname'] = $userById[$item['pid']]['wachat_nickname'];
                    $secondFans[$key]['pid_phone'] = $userById[$item['pid']]['phone'];

                }
            }
        }
        return success('间推用户', ['list' => $secondFans, 'count' => $count]);
    }


    public function commissionDetail(Request $request){
        $param = $request->param();
        $userCommissionModel = new UserCommission();
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $userCommission = $userCommissionModel
            ->where('receive_uid', '=', $request->userInfo['id'])
            ->limit($start,$limit)
             ->select()->toArray();
        $count = $userCommissionModel->where('receive_uid', '=', $request->userInfo['id'])->count();
        if ($userCommission){
            $triggeruUids= array_column($userCommission,'trigger_uid');
            $userModel = new \app\home\model\User();
            $userList = $userModel->where('id','in',$triggeruUids)->select()->toArray();
            $userListById = array_column($userList,null,'id');
            foreach ($userList as  $key => $item) {
                $userList[$key]['nickname'] = $userListById[$item['id']]['nickname'];
                $userList[$key]['avatar'] = $userListById[$item['id']]['avatar'];
                $userList[$key]['wachat_nickname'] = $userListById[$item['id']]['wachat_nickname'];
            }
        }
        return success('佣金明细',['list' => $userCommission,'count'=> $count]);
    }
    public function balance(Request $request){
        $param = $request->param();
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $AmountLog = new AmountLog();
        $where =  [['uid' , '=',$request->userInfo['id']]];
        if (isset($param['type']) && !empty($param['type'])){
            $where[]= ['type','=',$param['type']];
        }
        if (isset($param['start_time']) && !empty($param['start_time'])){
            $where[]= ['create_time','>=',strtotime($param['start_time'])];
        }
        if (isset($param['end_time']) && !empty($param['end_time'])){
            $where[]= ['create_time','<=',strtotime($param['end_time'])];
        }
        $list = $AmountLog
            ->limit($start, $limit)
            ->order('create_time','desc')
            ->where($where)
            ->select();

        $count = $AmountLog ->where($where)
            /*->where(function($query) use ($where){$query->whereOr($where);})*/->count();
        return success('余额', ['list' => $list, 'count' => $count]);
    }

    public function myTeam(Request $request){
        $userModel  = new \app\home\model\User();
        $yearTime  = strtotime(date('Y-01-01 00:00:00'));
        $monthTime  = strtotime(date('Y-m-01 00:00:00'));
        $todayTime  = strtotime(date('Y-m-d 00:00:00'));
        $firstUser = $userModel->where(['pid'=> $request->userInfo['id']])->select()->toArray();
        $info['total_commission'] = $request->userInfo['total_commission'];
        $info['team_count'] = 0;
        $info['team_today_count'] = 0;
        if ($firstUser){
            $info['team_count'] = count($firstUser);
            foreach ($firstUser as $firstValue){

                if (strtotime($firstValue['create_time']) > $todayTime ){
                    $info['team_today_count'] += 1;
                }
            }
            $firstUserId  = array_column($firstUser,'id');
            $secondUser =$userModel->where('pid','in', $firstUserId)->select()->toArray();

            if ($secondUser){
                $info['team_count'] += count($secondUser);
                foreach ($secondUser as $secondValue){
                    if (strtotime($secondValue['create_time']) >$todayTime ){
                        $info['team_today_count'] += 1;
                    }
                }
            }
        }
        $userCommissionModel = new UserCommission();
        $info['year_amount'] =$userCommissionModel->where(['receive_uid' => $request->userInfo['id']])
            ->where('create_time','>=',$yearTime)->sum('amount');
        $info['month_amount'] =$userCommissionModel->where(['receive_uid' => $request->userInfo['id']])
            ->where('create_time','>=',$monthTime)->sum('amount');
        $info['today_amount'] =$userCommissionModel->where(['receive_uid' => $request->userInfo['id']])
            ->where('create_time','>=',$todayTime)->sum('amount');
        return success('我的团队',$info);
    }


    public function integralLog(Request $request){
        $integralLog =  new IntegralLog();
        $where['uid']  = $request->userInfo['id'];
        $param = $request->param();
        if (isset($param['mode_type']) && !empty($param['mode_type'])){
            $where['mode_type']  = $param['mode_type'];
        }
        if (isset($param['type']) && !empty($param['type'])){
            $where['type']  = $param['type'];
        }
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $list =  $integralLog->where($where)->limit($start,$limit)
            ->order('create_time','desc')

            ->select()->toArray();
        $count  =  $integralLog->where($where)->count();
        return success('积分记录',['list' => $list,'count' => $count]);
    }

    public function expenditure(Request $request){
        $amountLog =  new AmountLog();
        $where[]  = ['uid','=',$request->userInfo['id']];
        $where[]  = ['operate_type','in',[2,3]];
        $where[]  = ['pay_method','=',4];
        $param = $request->param();

        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $list = $amountLog->where($where)->limit($start,$limit)->select()->toArray();
        $count = $amountLog->where($where)->count();
        return success('积分记录',['list' => $list,'count' => $count]);
    }
    /**
    只是 退款不会影响其他逻辑
     */
    public function amountRefund(Request $request){
        $param = $request->param();
        if ($param['type'] == 1){ // 充值
            $Recharge  =  new Recharge();
            $info  =$Recharge->where(['id' => $param['id']])->find();

            if ($info['type'] == 1){
                $Offiaccount =  new Offiaccount();
                $data  =   $Offiaccount->wechatReturns(['reality_amount' => $info['amount'],'sn_order' => $info['sn_order']],getOrderNo('tu_'));
            }elseif($info['type'] == 6 ){
                $Offiaccount =  new Offiaccount();
                $data  =  $Offiaccount->wechatsecapiReturns(['sn_order' => $info['sn_order'],'amount' => $info['amount']]);
            }elseif($info['type'] == 7 ){
                $Offiaccount =  new \app\services\alipay\Offiaccount();
                $data  =  $Offiaccount->refund(['sn_order' => $info['sn_order'],'reality_amount'=> $info['amount']]);
            }
        }elseif($param['type'] == 2 ){   // 订单
            $GoodsOrder =  new GoodsOrder();
            $info  = $GoodsOrder->where(['id' => $param['id']])->find();
            if ($info['pay_way'] == 2){
                if ($info['pay_destination'] == 2){ // 普通商户退款
                    $Offiaccount =  new Offiaccount();
                    $Offiaccount->wechatReturns(['reality_amount' => $info['reality_amount'],'sn_order' => $info['sn_order']], getOrderNo('tu_'));
                }else{ // 服务商商户退款
                   $Offiaccount =  new Offiaccount();
                    $data  =   $Offiaccount->mwechatReturns(['reality_amount' => $info['reality_amount'],'sn_order' => $info['sn_order']] ,getOrderNo('tu_'));
                }
            }elseif($info['pay_way'] == 7 ){

                $Offiaccount =  new Offiaccount();
                $data  =   $Offiaccount->wechatsecapiReturns(['sn_order' => $info['sn_order'],'amount'=>$info['reality_amount']]);
            }elseif($info['pay_way'] == 8 ){
                $Offiaccount =  new \app\services\alipay\Offiaccount();
                $data  =   $Offiaccount->refund(['sn_order' => $info['sn_order'],'reality_amount'=> $info['reality_amount']]);

            }
        }elseif($param['type'] == 3 ){   // 订单
            $PackageOrder=  new PackageOrder();
            $info  = $PackageOrder->where(['id' => $param['id']])->find();
            if ($info['pay_type'] == 2){
                $Offiaccount =  new Offiaccount();
                $Offiaccount->wechatReturns(['reality_amount' => $info['price'],'sn_order' => $info['order_sn']], getOrderNo('tu_'));

            }elseif($info['pay_type'] == 7 ){
                $Offiaccount =  new Offiaccount();
                $Offiaccount->wechatsecapiReturns(['sn_order' => $info['order_sn'],'amount'=>$info['price']]);
            }elseif($info['pay_type'] == 8 ){
                $Offiaccount =  new \app\services\alipay\Offiaccount();
                $test = $Offiaccount->refund(['sn_order' => $info['order_sn'],'reality_amount'=> $info['price']]);


            }
        }else{
            $GoodsOrder =  new UserConsumption();
            $info  = $GoodsOrder->where(['id' => $param['id']])->find();
            if ($info['pay_type'] == 2){
                if ($info['pay_destination'] == 2){ // 普通商户退款
                    $Offiaccount =  new Offiaccount();
                    $Offiaccount->wechatReturns(['reality_amount' => $info['reality_amount'],'sn_order' => $info['sn_order']], getOrderNo('tu_'));
                }else{ // 服务商商户退款
                    $Offiaccount =  new Offiaccount();
                    $data  =    $Offiaccount->mwechatReturns(['reality_amount' => $info['amount'],'sn_order' => $info['sn_order']] ,getOrderNo('tu_'));
                }
            }elseif($info['pay_type'] == 7  ){

                $Offiaccount =  new Offiaccount();
                $data  =  $Offiaccount->wechatsecapiReturns(['sn_order' => $info['sn_order'],'amount'=>$info['amount']]);
            }elseif($info['pay_type'] == 8 || $info['pay_type'] == 10 ){
                $Offiaccount =  new \app\services\alipay\Offiaccount();
                $data  =  $Offiaccount->refund(['sn_order' => $info['sn_order'],'reality_amount'=> $info['amount']]);

            }

        }
        var_dump( $data );
    }
}
